package com.dave.gd.core.rule;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.dave.gd.core.base.entity.impl.AbstractBaseEntity;

/**
 * @Class: RuleResult
 * @see com.ctg.itrdc.core.rule.RuleResult
 */
public class RuleResult implements Serializable {
    private Long ruleId;
    private Long ruleSeq;
    private String ruleCode;
    private String ruleMsg;
    private String hintCode;
    private ERuleRes ruleResult; // 通过、不通过、警告、需用户确认
    private boolean isMultiOption; // 单选、多选
    private boolean isOnlyOneGroupCheck = false; //是否只能有个分组可以选择。
    private List<RuleOption> options = new ArrayList<RuleOption>(0);
    private boolean isWarning = false;
    private boolean isCancelDisabled = false;
    private transient AbstractBaseEntity source;
    
    private String className;
    
    private String pkAttr;
    
    private String entityId;
    
    private boolean isAssert = false; //标记确认类结果是否已经执行过。
    
    public String getClassName() {
        return className;
    }
    
    public void setClassName(String className) {
        this.className = className;
    }
    
    public String getPkAttr() {
        return pkAttr;
    }
    
    public void setPkAttr(String pkAttr) {
        this.pkAttr = pkAttr;
    }
    
    public String getEntityId() {
        return entityId;
    }
    
    public void setEntityId(String id) {
        this.entityId = id;
    }
    
    public boolean isAssert() {
        return isAssert;
    }
    
    public void setAssert(boolean isAssert) {
        this.isAssert = isAssert;
    }
    
    /**
     * 规则提示编码.
     */
    private String ruleHintCode;
    
    public Long getRuleId() {
        return ruleId;
    }
    
    public void setRuleId(Long ruleId) {
        this.ruleId = ruleId;
    }
    
    public Long getRuleSeq() {
        return ruleSeq;
    }
    
    public void setRuleSeq(Long ruleSeq) {
        this.ruleSeq = ruleSeq;
    }
    
    public String getRuleCode() {
        return ruleCode;
    }
    
    public void setRuleCode(String ruleCode) {
        this.ruleCode = ruleCode;
    }
    
    public String getRuleMsg() {
        return ruleMsg;
    }
    
    public void setRuleMsg(String ruleMsg) {
        this.ruleMsg = ruleMsg;
    }
    
    public String getHintCode() {
        return hintCode;
    }
    
    public void setHintCode(String hintCode) {
        this.hintCode = hintCode;
    }
    
    public ERuleRes getRuleResult() {
        return ruleResult;
    }
    
    public void setRuleResult(ERuleRes ruleResult) {
        this.ruleResult = ruleResult;
    }
    
    public boolean isMultiOption() {
        return isMultiOption;
    }
    
    public void setMultiOption(boolean isMultiOption) {
        this.isMultiOption = isMultiOption;
    }
    
    public boolean isOnlyOneGroupCheck() {
        return isOnlyOneGroupCheck;
    }
    
    public void setOnlyOneGroupCheck(boolean isOnlyOneGroupCheck) {
        this.isOnlyOneGroupCheck = isOnlyOneGroupCheck;
    }
    
    public List<RuleOption> getOptions() {
        return options;
    }
    
    public void setOptions(List<RuleOption> options) {
        this.options = options;
    }
    
    public boolean isWarning() {
        return isWarning;
    }
    
    public void setWarning(boolean isWarning) {
        this.isWarning = isWarning;
    }
    
    public boolean isCancelDisabled() {
        return isCancelDisabled;
    }
    
    public void setCancelDisabled(boolean isCancelDisabled) {
        this.isCancelDisabled = isCancelDisabled;
    }
    
    public AbstractBaseEntity getSource() {
        return source;
    }
    
    public void setSource(AbstractBaseEntity source) {
        this.source = source;
    }
    
    public String getRuleHintCode() {
        return ruleHintCode;
    }
    
    public void setRuleHintCode(String ruleHintCode) {
        this.ruleHintCode = ruleHintCode;
    }
    
    /**
     *
     * 获取提示名称.
     *
     * @return String 提示名称
     * 
     */
    public String getRuleResultName() {
        switch (ruleResult) {
            case SUCCESS:
                return "通过";
            case WARNING:
                return "警告";
            case ERROR:
                return "不通过";
            case COMFIRM:
                return "用户确认";
            default:
                return "未知类型";
                
        }
    }
    
    /**
     *
     * .
     *
     * @return 获取错误信息，会拼装自动选项。
     * 
     */
    public String getErrorMsg() {
        StringBuffer result = new StringBuffer();
        if (this.getRuleResult() == ERuleRes.ERROR) {
            result.append("规则执行:");
            result.append(this.ruleMsg);
            if (options != null) {
                for (RuleOption op : options) {
                    result.append("\n");
                    result.append(op.getOptionName());
                }
            }
        }
        
        return result.toString();
    }
}
